package me.shurufa.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.Bind;
import me.shurufa.R;
import me.shurufa.fragments.BookDigestModifyFragment;
import me.shurufa.model.NewDigest;
import me.shurufa.utils.Constants;

/**
 * 作者 : andy
 * 日期 : 16/3/14 14:19
 * 邮箱 : andyxialm@gmail.com
 * 描述 : 书摘添加笔记界面
 */
public class BookDigestModifyActivity extends BaseActivity implements View.OnClickListener {


    @Bind(R.id.left_text)
    TextView leftText;

    @Bind(R.id.right_image)
    ImageView rightImage;

    @Bind(R.id.right_text)
    TextView rightText;

    @Bind(R.id.toolbar_title)
    TextView toolbar_title;

    private NewDigest mDigest;
    private BookDigestModifyFragment mDigestModifyFragment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        activity_layout_res = R.layout.activity_digest_add_note;
        super.onCreate(savedInstanceState);
        parseArguments();
        initUI();
    }

    /**
     * 传参
     * @param in
     * @param digest
     */
    public static void initArguments(Intent in, NewDigest digest) {
        in.putExtra(Constants.ARG_MODIFY_DIGEST, digest);
    }

    /**
     * 解析参数
     */
    private void parseArguments() {
        this.mDigest = (NewDigest) getIntent().getSerializableExtra(Constants.ARG_MODIFY_DIGEST);
    }


    private void initUI() {
        titleTextView.setText(R.string.add_note);
        rightText.setText(getString(R.string.next));
        rightText.setVisibility(View.VISIBLE);
        rightText.setOnClickListener(this);

        initFragment();
    }

    private void initFragment() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        mDigestModifyFragment = BookDigestModifyFragment.create(mDigest);
        ft.replace(R.id.fragment_container, mDigestModifyFragment);
        ft.commit();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.right_text:
                if (checkData()) {
                    onNext();
                }
                break;
        }
    }

    /**
     * 右上角点击下一步
     */
    private void onNext() {
        Intent in = new Intent(this, SelectCatalogActivity.class);
        // SelectCatalogActivity.initArguments(in, mAddDigestBean);
        startActivity(in);
        this.finish();
    }

    /**
     * 校验数据
     * @return
     */
    private boolean checkData() {
        /*if (null == mAddDigestBean) {
            Utils.showToast(getString(R.string.write_book_digest));
            return false;
        }

        if (TextUtils.isEmpty(mAddDigestBean.content)) {
            Utils.showToast(getString(R.string.write_book_digest));
            return false;
        }

        if ("0".equals(mAddDigestBean.excerptedBookId) || TextUtils.isEmpty(mAddDigestBean.excerptedBookTitle)) {
            Utils.showToast(getString(R.string.select_book_digest));
            return false;
        }*/
        return true;
    }

}
